﻿namespace Creek.UI.EFML.Base.JS.ScriptingTypes
{
    using System.Windows.Forms;

    public class Document
    {
        #region Constructors and Destructors

        public Document(UI.EFML.Document d, FlowLayoutPanel layout)
        {
            this.D = d;
            this.Layout = layout;
            foreach (UiElement elementBase in d.Body)
            {
                this.all[elementBase.ID] = elementBase;
            }
        }

        #endregion

        #region Public Properties

        public UI.EFML.Document D { get; set; }

        public FlowLayoutPanel Layout { get; set; }

        public DocumentAll all
        {
            get
            {
                return new DocumentAll(this.Layout);
            }
        }

        #endregion

        #region Public Methods and Operators

        public IUIElement GetElementById(string id)
        {
            foreach (Control control in this.Layout.Controls)
            {
                if (control.Name == id)
                {
                    return (IUIElement)control;
                }
            }
            return null;
        }

        public IUIElement GetElementsByTagname(string name)
        {
            foreach (Control control in this.Layout.Controls)
            {
                if ((string)control.Tag == name)
                {
                    return (IUIElement)control;
                }
            }
            return null;
        }

        #endregion
    }
}